define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'article/article/index' + location.search,
                    add_url: 'article/article/add',
                    edit_url: 'article/article/edit',
                    del_url: 'article/article/del',
                    multi_url: 'article/article/multi',
                    import_url: 'article/article/import',
                    table: 'article',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'fenlei.title', title: __('分类'), operate: 'LIKE'},
                        {field: 'path_imgimage', title: __('Path_imgimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'is_shopdata', title: __('Is_shopdata'), searchList: {"1":__('Is_shopdata 1'),"2":__('Is_shopdata 2')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $("input[name='row[type]']").on('click',function(){
                var val = $(this).val();
                if(val==1)
                {
                    $('#zhu1').attr('hidden',false);
                    $('#zhu2').attr('hidden',true);
                    $('#c-zhu_images').val('');
                    $('#p-zhu_images').html('');
                }
                else
                {
                    $('#zhu1').attr('hidden',true);
                    $('#zhu2').attr('hidden',false);
                    $('#c-zhu_images2').val('');
                    $('#p-zhu_images2').html('');
                }
            });
        },
        edit: function () {
            Controller.api.bindevent();
            var id =$('#type').val();

            $("input[name='row[type]']").on('click',function(){
                var val = $(this).val();
                if(val==1)
                {
                    $('#zhu1').attr('hidden',false);
                    $('#zhu2').attr('hidden',true);
                    if(val!=id)
                    {
                        $('#c-zhu_images').val('');
                        $('#p-zhu_images').html('');
                    }
                }
                else
                {
                    $('#zhu1').attr('hidden',true);
                    $('#zhu2').attr('hidden',false);
                    if(val!=id)
                    {
                        $('#c-zhu_images2').val('');
                        $('#p-zhu_images2').html('');
                    }

                }
            });
        },
        api: {
            bindevent: function () {

                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});